package com.zygh.policeasset.mapper;

import com.zygh.policeasset.pojo.Contract;
import com.zygh.policeasset.pojo.RepairAccept;
import com.zygh.policeasset.pojo.RoadCross;
import com.zygh.policeasset.pojo.vo.RepairAcceptVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RepairAcceptMapper {

    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @Insert("insert into repair_accept (type,repair_ids,order_user_id,content,flow_no) " +
            "values(#{type,jdbcType=VARCHAR},#{repairIds,jdbcType=VARCHAR}," +
            "#{orderUserId,jdbcType=VARCHAR},#{content,jdbcType=VARCHAR},#{flowNo,jdbcType=VARCHAR})")
    Integer add(RepairAccept repairAccept);

    @Delete("delete from repair_accept where id = #{id} ")
    Integer delete(@Param("id") Integer num);

    @Results(id = "map", value = {@Result(property = "repairIds", column = "repair_ids"),
            @Result(property = "orderUserId", column = "order_user_id"),
            @Result(property = "flowNo", column = "flow_no")})
    @Select("<script>" +
            "select ra.*,af.app_status,af.approval_steps_id as approvalStepsId,u.name as orderUserName,af.app_status as appStatus from repair_accept ra " +
            "left join audit_flow af on ra.flow_no = af.flow_no " +
            "left join user u on af.applicant = u.id " +
            "<where>"+
            "<if test=' status != null'> and af.app_status = #{status} </if>"+
            "<if test=' userId != null'> and order_user_id = #{userId} </if>"+
            "</where>  order by id desc"+
            "</script>" )
    List<RepairAcceptVO> findall(Integer userId,Integer status);

    @ResultMap({"map"})
    @Select("<script>" +
            "select ra.*,af.app_status,af.approval_steps_id as approvalStepsId,u.name as orderUserName,af.app_status as appStatus from repair_accept ra " +
            "left join audit_flow af on ra.flow_no = af.flow_no " +
            "left join user u on af.applicant = u.id " +
            "<where>"+
            "<if test=' id != null'> and ra.id = #{id} </if>"+
            "</where>  order by id desc"+
            "</script>" )
    RepairAcceptVO selectById(Integer id);

    @Update({"<script>" +
            "update repair_accept  " +
            "<set> " +
            " <if test='type != null and type.length &gt; 0'>type = #{type},</if>" +
            " <if test='repairIds != null and repairIds.length &gt; 0'>repair_ids = #{repairIds},</if>" +
            " <if test='orderUserId != null '>order_user_id = #{orderUserId},</if>" +
            " <if test='content != null and content.length &gt; 0'>content = #{content},</if>" +
            " <if test='flowNo != null and flowNo.length &gt; 0'>flow_no = #{flowNo},</if>" +
            "</set>" +
            "<where> " +
            "<if test='id != null'> " +
            "id = #{id} " +
            "</if>" +
            "</where>" +
            "</script>"})
    Integer updateById(RepairAccept repairAccept);

   /* @Select({"<script>", "select t.*,cp.company_name,p.name as project_name,s.section_name," +
            "cy.type as type,st.audit_amount,af.app_status,af.approval_steps_id as approvalStepsId,u.name as userName from contract t " +
            "left join section s on t.section_id = s.id left join project p on t.project_no = p.project_no " +
            "left join audit_flow af on t.flow_no = af.flow_no left join user u on af.applicant = u.id " +
            "left join category cy on p.category = cy.id left join company cp on t.company_id = cp.id " +
            "left join settlement st on t.section_id = st.section_id  and t.project_no = st.project_no <where><if test='name != null " +
            "and name.length &gt; 0'> and p.name like '%${name}%' </if><if test='category != null and category &gt; 0'>and p.category=#{category} </if>" +
            "<if test='companyId != null '> and t.company_id = #{companyId} </if>" +
            "<if test='time1 != null and time2 != null and time1.length &gt; 0 and time2.length &gt; 0'> and t.confirm_time between #{time1} and  #{time2} </if>" +
            "<if test='userId != null '> and af.applicant=#{userId} </if>" +
            "<if test=' status != null'> and af.app_status = #{status} </if></where>order by t.id desc </script>"})
    @Results({@Result(property = "projectNo", column = "project_no"), @Result(property = "projectName", column = "project_name"), @Result(property = "sectionId", column = "section_id"), @Result(property = "companyId", column = "company_id"), @Result(property = "companyName", column = "company_name"), @Result(property = "contractNo", column = "contract_no"), @Result(property = "timeInterval", column = "time_interval"), @Result(property = "startTime", column = "start_time"), @Result(property = "endTime", column = "end_time"), @Result(property = "confirmTime", column = "confirm_time"), @Result(property = "paymentMethod", column = "payment_method"), @Result(property = "sectionName", column = "section_name"), @Result(property = "expectedInvisibleAmount", column = "expected_invisible_amount"), @Result(property = "expectedFixedAmount", column = "expected_fixed_amount"), @Result(property = "companyDesign", column = "company_design"), @Result(property = "auditAmount", column = "audit_amount"), @Result(property = "flowNo", column = "flow_no"), @Result(property = "appStatus", column = "app_status")})
    List<Contract> findAll(@Param("name") String str, @Param("status") Integer num, @Param("companyId") Integer num2, @Param("time1") String str2, @Param("time2") String str3, @Param("category") Integer num3, @Param("userId") Integer num4);
*/
}